//
//  MainTabBar.swift
//  sinaBlog
//
//  Created by tianxiangyang on 15/12/12.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(compose)
    }

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func layoutSubviews() {
        
        let w = self.bounds.width / 5
        
        let h = self.bounds.height
        
        var x:CGFloat = 0
        
        let y:CGFloat = 0
        
        var index: CGFloat = 0
        
        var rect = CGRect(x: x, y: y, width: w, height: h)
        
        for subview in subviews{
            
        if subview.isKindOfClass(NSClassFromString("UITabBarButton")) {
            
            (subview as! UIView).frame = CGRectOffset(rect, w * index, 0)
            
    
            if index == 1 {
            index++
            }
            
            index++
            
            }
   
        }
        
        
        compose.frame = CGRect(x: 2 * w , y: 0, width: w, height: h)
        
    }
    
    
    lazy var compose: UIButton = UIButton(imageName: "tabbar_compose_icon_add", backImageName:"tabbar_compose_button")
    

}








